package com.petc.api.service.impl.base;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.petc.api.entity.DeviceBind;
import com.petc.api.mapper.DeviceBindMapper;
import com.petc.api.service.base.DeviceBindService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class DeviceBindServiceImpl extends ServiceImpl<DeviceBindMapper, DeviceBind> implements DeviceBindService {

    @Resource
    private DeviceBindMapper deviceBindMapper;


    @Override
    public DeviceBind queryByUserId(Integer userId) {
        LambdaQueryWrapper<DeviceBind> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DeviceBind::getUserId, userId);
        queryWrapper.eq(DeviceBind::getBindState, 0);
        return deviceBindMapper.selectOne(queryWrapper);
    }

    @Override
    public void update(DeviceBind deviceBind) {
        deviceBindMapper.updateById(deviceBind);
    }

    @Override
    public void insert(DeviceBind deviceBind) {
        deviceBindMapper.insert(deviceBind);
    }
}
